//
//  HorizontalViewController.m
//  LewPhotoBrowser
//
//  Created by pljhonglu on 15/5/19.
//  Copyright (c) 2015年 pljhonglu. All rights reserved.
//

#import "HorizontalViewController.h"
#import "LewReorderableLayout.h"
#import "LewCollectionViewCell.h"

#define cellIdentifier @"LewCollectionViewCell"

@interface HorizontalViewController ()<LewReorderableLayoutDelegate, LewReorderableLayoutDataSource>
@property (nonatomic, strong)NSMutableArray *images;
@property (nonatomic, strong) UICollectionView *collectionView;
@end

@implementation HorizontalViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    
    LewReorderableLayout *layout = [[LewReorderableLayout alloc]init];
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;   //设置滚动方向
    self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - SCALE_HIGHT(400)) collectionViewLayout:layout];
    
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    
    self.collectionView.showsVerticalScrollIndicator = NO;    //设置滚动条
    self.collectionView.showsHorizontalScrollIndicator = NO;
    
    self.collectionView.backgroundColor = [UIColor whiteColor];
    self.collectionView.bounces = YES;
    [self.collectionView registerClass:[LewCollectionViewCell class] forCellWithReuseIdentifier:cellIdentifier];
    [self.view addSubview:_collectionView];
    [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.view);
        make.left.right.mas_equalTo(self.view);
        make.bottom.mas_equalTo(self.view);
    }];
    
    _images = @[].mutableCopy;
    for (int i = 0; i<100; i++) {
        NSString *imageName = [NSString stringWithFormat:@"Sample%d.jpg",i%30];
        UIImage *image = [UIImage imageNamed:imageName];
        [_images addObject:image];
    }

}


#pragma mark - LewReorderableLayoutDataSource
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    LewCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
    cell.imageView.image = _images[indexPath.item];
    return cell;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return _images.count;
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}

@end
